package com.hinnotek.amoeba.ui.activity.old

import android.os.Bundle
import android.view.*
import com.lee.common.base.BaseActivity
import com.hinnotek.amoeba.R
import com.hinnotek.amoeba.bean.old.PurchaseAddBeanTo
import com.hinnotek.amoeba.databinding.ActivitySellPurchaseRequisitionSuccessBinding
import com.hinnotek.amoeba.utilities.IntentUtils
import java.util.*


class SellPurchaseRequisitionSuccessActivity : BaseActivity<ActivitySellPurchaseRequisitionSuccessBinding>() {

    private var maxS = 3
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_sell_purchase_requisition_success)
        val to = intent.getSerializableExtra("purchaseAddBeanTo") as PurchaseAddBeanTo?
        val purchase_type_to = intent.getStringExtra("purchase_type_to")
        val timer = Timer()
        val timerTask: TimerTask = object : TimerTask() {
            override fun run() {
                runOnUiThread {
                    bindingView.tvS.text = (maxS - 1).toString() + "s"
                    maxS -= 1
                    if (maxS == 0) {
                        timer.cancel()
                        val bundle = Bundle()
                        bundle.putSerializable("purchaseAddBeanTo", to)
                        bundle.putString("purchase_type_to", purchase_type_to)
                        IntentUtils.startActivity(
                            mContext,
                            SellProjectRequirementsAddActivity::class.java, bundle
                        )
                        finish()
                    }
                }
            }
        }
        timer.schedule(timerTask, 0, 1000)
       bindingView.superTo.setOnClickListener { v: View? ->
           timerTask.cancel()
           timer.cancel()
           val bundle = Bundle()
           bundle.putSerializable("purchaseAddBeanTo", to)
           bundle.putString("purchase_type_to", purchase_type_to)
           IntentUtils.startActivity(this, SellProjectRequirementsAddActivity::class.java, bundle)
           finish()
       }
    }

    override fun initVew() {}
    override fun setData() {}
}